//
// Created by lijia on 2021/1/12.
//

#ifndef PERISCOPE_GPS_H
#define PERISCOPE_GPS_H

#include "stm32f1xx_hal.h"

typedef struct {
	// positions are in s5.4 format
	int32_t lat;
	int32_t lng;
	// elevation is in sx.1 format
	int32_t elevation;

	float precision;
	uint8_t fixState;
	uint8_t satCount;

	uint32_t frame;
} GpsData;

extern void gps_init(UART_HandleTypeDef *, DMA_HandleTypeDef *);

extern void gps_tick();

extern const GpsData *gps_get_last_frame();

extern int32_t parse_latitude(const uint8_t *);

extern int32_t parse_direct_latitude(const uint8_t *);

extern int32_t parse_longitude(const uint8_t *);

extern int32_t parse_direct_longitude(const uint8_t *);

extern float gps_dot4_to_deg(int32_t x);

extern int32_t gps_dm6_to_ddd(int32_t x);

extern void gps_angle(int32_t* lat1, int32_t* lon1, int32_t* lat2, int32_t* lon2, int32_t* bearing);

extern void gps_distance_cm(int32_t* lat1, int32_t* lon1, int32_t* lat2, int32_t* lon2, uint32_t* dist);

#endif //PERISCOPE_GPS_H
